package com.cqndt.disaster.device.controller;

import java.util.Map;
import java.util.List;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSONArray;
import org.springframework.util.StringUtils;
import com.cqndt.disaster.device.util.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cqndt.disaster.device.service.TabAlarmConfigService;

/**
 * @author lgb
 * @date 2020-8-29
 * @说明  报警阀值控制
 **/
@RestController
@RequestMapping("/alarm_config")
public class TabAlarmConfigController {
	
	@Resource
	private TabAlarmConfigService tacService;
	
	/**
	 * @param deviceNo
	 * @return 根据设备编号查询配置信息
	 **/
	@GetMapping(value="findListByNo")
    public Result listByNo(String deviceNo){
		Result result = new Result();
		if(StringUtils.isEmpty(deviceNo)) {
			return result.failure(400,"设备编号为空");
		}
        List<Map<String,Object>> data=tacService.findListByNo(deviceNo);
        result.setCount(data.size());
        result.setData(data);
        return result;
    }

	/**
	 * @param thresholdList
	 * @return 编辑阀值配置
	 **/
	@PostMapping(value="updateConfig")
	public Result updateConfig(String thresholdList) {
		Result result = new Result();
		if(thresholdList.isEmpty()) {
			return result.failure(400,"请求数据为空");
		}
		try {
			JSONArray list = JSONArray.parseArray(thresholdList);
			tacService.updateConfig(list);
		} catch (Exception e) {
			return result.failure(400,e.getMessage());
		}
		return result.success("编辑阀值成功");
	}
	
}